$(start);

function start() {
    //	test();
    init();
}


function init() {
    initLayout();
    initMenu();

    function initLayout() {
        var pageNode = $('#page');


    }


    function initMenu() {
        var menuNode = $('#menu');
        menuNode.tree({
            data: menuData,
            onClick: function (node) {
                showFrame(node.id);
            }
            ,
            onContextMenu: function (e, node) {
                e.preventDefault();
                showFrame(node.id, true);
            },
            onDblClick: function (node) {
                showFrame(node.id, true);
            }
        });


    }
}


// 展示某个界面

function showFrame(fid, isRefresh) {

    var opDistNode = $('#page').layout('panel', 'center');

    console.log(opDistNode);
    // 初始化
    init(fid, isRefresh);
    // 隐藏兄弟元素,显示自己
    toogle(fid);


    function init(fid, isRefresh) {
        if (isRefresh) {
            opDistNode.find('#' + fid).remove();
        }

        var node = opDistNode.find('#' + fid);
        if (!node.length) {
            node = $('<iframe id="' + fid + '" />').attr('src', getUrl(fid)).css({
                'border': 'none',
                'width': '100%',
                'height': '100%'
            });
            opDistNode.append(node);
        }

        function getUrl(fid) {
            return 'pages/' + fid + '.html';
        }
    }

    function toogle(fid) {
        var node = opDistNode.find('#' + fid);
        node.siblings().hide();
        node.show();
    }
}



var menuData = [{
    id: "items",
    text: "项目",
    "state": "open",
    children: [{
        id: "bag",
        text: "标签包"
    }, {
        id: "tag",
        text: "标签"
    }, {
        id: "video",
        text: "视频"
    }, {
        id: "finder",
        text: "搜索器"
    }, {
        id: "subscribe",
        text: "订阅"
    }, {
        id: "syno",
        text: "同义词"
    }]
}, { id: "user", text: "用户", children: [] }, {
    id: "report",
    text: "报表",
    children: [{
        id: "button",
        text: "Button"
    }, {
        id: "listbox",
        text: "ListBox"
    }, {
        id: "checkboxlist",
        text: "CheckBoxList"
    }, {
        id: "radiolist",
        text: "RadioList"
    }, {
        id: "calendar",
        text: "Calendar"
    }, {
        id: "textbox",
        text: "TextBox"
    }, {
        id: "password",
        text: "Password"
    }, {
        id: "textarea",
        text: "TextArea"
    }, {
        id: "combobox",
        text: "ComboBox"
    }, {
        id: "datepicker",
        text: "DatePicker"
    }, {
        id: "spinner",
        text: "Spinner"
    }, {
        id: "treeselect",
        text: "TreeSelect"
    }, {
        id: "fileupload",
        text: "FileUpload"
    }]
}];